<%--
  Created by IntelliJ IDEA.
  User: Chen
  Date: 2016/4/19
  Time: 17:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <base href="<%=basePath%>" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>AjaxFileupload</title>
    <script type="text/javascript" src="assets/js/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="assets/js/ajaxfileupload.js"></script>
</head>
<body>
    <input type="file" id="file" name="file" onchange="ajaxFileUpload();"/>
    <img src="uploadImage/IMG_8441.jpg" alt="头像">

    <script type="text/javascript">
        //ajax 实现文件上传
        function ajaxFileUpload() {

            $.ajaxFileUpload({
                url: "upload/imageUpload",
                secureuri: false,
                data: {
                    filePre: "feedback",
                    p: new Date()
                },
                fileElementId: "file",
                dataType: "json",
                success: function (data) {
                    if (data.status == "success") {
                        //上传成功
                    }
                    switch (data.message) {
                        //解析上传状态
                        case "0" : //上传成功
                            break;
                        case "-1" : //上传文件不能为空
                            break;
                        default: //上传失败
                            break;
                    }
                },
                error: function (data) {
                    //上传失败
                }
            });
        }
    </script>
</body>
</html>
